  set more off
  set seed 1234

* Log
  capture log close
  log using "$logs\descriptive_analysis.txt", text replace

* Date
  display "$S_TIME  $S_DATE"

*===================================================================*
*   BIHAR EVALUATION OF SOCIAL FRANCHISING AND TELEMEDICINE (BEST)
*              Descriptive statistics and Main analysis
*
* Last updated: 07/02/2014
*===================================================================*

*********************************************************************
* Table 1: Providers Characteristics - First Part (continue below)
* Format Mean(SD) for each group, Difference (95% CI) and p-value
*********************************************************************
* Open Data
  use "$prodata\providers_interview", clear
  count
  merge 1:1 prov_id using "$prodata\SPP_prov_list"
  keep if _merge==3
  drop _merge

* Define local with variables to describe
  gen     homeo_ayu = 0
  replace homeo_ayu = 1 if homeopathic==1 | ayurvedic==1
  gen miss=.
  #delimit ;
  local table1 "age high_school comp_ever experience npatient work_hs_f 
                camps fac_gov iindex c_fee miss consult adm_treat sell_drug 
		lab_duty adm_duty owner miss allopathic homeo_ayu miss 
		diarrhea pneumonia";
  #delimit cr

* Matrix to store output
  local cword : word count `table1'
  mat table1= J(`cword'+7, 10,.)

* Loop over variables
  local i = 1
  foreach var of local table1 {
  quietly count if `var'!=.
    if r(N)==0 {
    local i = `i' + 1
    }
    else {

* Mean and Std. Dev.
  quietly ttest `var', by(mqualif)

  if "`var'"=="age" | "`var'"=="experience" | "`var'"=="work_hs_f" | "`var'"=="npatient" | "`var'"=="iindex" | "`var'"=="c_fee" {
      local m1 = r(mu_1)
      local m2 = r(mu_2)
      local sd1 = r(sd_1)
      local sd2 = r(sd_2)
      }

  else {
      local m1 = r(mu_1)*100
      local m2 = r(mu_2)*100
      local sd1 = r(sd_1)*100
      local sd2 = r(sd_2)*100
	}

  matrix table1[`i',1] = `m1'
  matrix table1[`i',2] = `sd1'
  matrix table1[`i',3] = r(N_1)
  matrix table1[`i',4] = `m2'
  matrix table1[`i',5] = `sd2'
  matrix table1[`i',6] = r(N_2)

* Perform Mean Test and save results
  quietly reg `var' mqualif, cluster(cluster)

* Mean difference
  if "`var'"=="age" | "`var'"=="experience" | "`var'"=="work_hs_f" | "`var'"=="npatient" | "`var'"=="iindex" | "`var'"=="c_fee" {
      local dif = _b[mqualif]
      }

  else {
      local dif = _b[mqualif]*100
	}

  matrix table1[`i',7] = `dif'

* Lower and upper bounds of the confidence interval
  if "`var'"=="age" | "`var'"=="experience" | "`var'"=="work_hs_f" | "`var'"=="npatient" | "`var'"=="iindex" | "`var'"=="c_fee" {
  local ci_lower = _b[mqualif] - invttail(e(df_r),0.025)*_se[mqualif]
  matrix table1[`i',8] = `ci_lower'
  local ci_upper = _b[mqualif] + invttail(e(df_r),0.025)*_se[mqualif]
  matrix table1[`i',9] = `ci_upper'
  }
  else {
  local ci_lower = (_b[mqualif] - invttail(e(df_r),0.025)*_se[mqualif])*100
  matrix table1[`i',8] = `ci_lower'
  local ci_upper = (_b[mqualif] + invttail(e(df_r),0.025)*_se[mqualif])*100
  matrix table1[`i',9] = `ci_upper'
  }

* P-value
  matrix table1[`i',10] = (2 * ttail(e(df_r), abs(_b[mqualif]/_se[mqualif])))

  local i = `i' + 1
	}
    }

  mat colnames table1 = NMQ_mean NMQ_sd NMQ_N MQ_mean MQ_sd mean_diff MQ_N ci_lower ci_upper pvalue
  mat rownames table1 = `table1' miss KS KS_d KS_p PS PS_d Ps_p
  mat list table1


* Testing clustered proportion chi-squared
  local prop "high_school comp_ever camps fac_gov consult adm_treat sell_drug lab_duty adm_duty owner allopathic homeo_ayu diarrhea pneumonia"
  foreach v of local prop {
    di in red "`v'"
    clchi2 `v' mqualif, cluster(cluster)
    clttest `v', cluster(cluster) by(mqualif)
    }



*********************************************************************
* Table 2: Vignettes 
* Adherence to check list
*********************************************************************

* Open Data A - items
  use "$irtdata\vig_items_13.dta", clear
  count

  merge 1:1 prov_id using "$prodata\SPP_prov_list"
  keep if _merge==3
  drop _merge

  merge 1:1 prov_id using "$prodata\providers_interview", keepus(prov_id)
  keep if _merge==3
  drop _merge


* Fraction of positive response
  mat table2=J(60,3,.)

  local i 1
  foreach n in 1 2 3 4 5 6 7 8 9 10 12 13 14 16 17 18 19 20 { 
  quietly sum vg_item`n'
  mat table2[`i',1]=r(N)*r(mean)
  mat table2[`i',2]=r(mean)*100
  mat table2[`i',3]=r(sd)*100
  local i = `i'+1
  }


  local i=31
  foreach n in 21 22 23 24 25 27 28 29 30 31 32 33 34 35 36 37 38 39 40 { 
  quietly sum vg_item`n'
  mat table2[`i',1]=r(N)*r(mean)
  mat table2[`i',2]=r(mean)*100
  mat table2[`i',3]=r(sd)*100
  local i = `i'+1
  }

* either skin between ribs or nostrils appear to be flaring...item 28 and 29
  gen either = (vg_item28==1 | vg_item29==1)
  sum either

* weakness, irritability, ability to take fluids, and urinary frequency
  cap drop either
  gen either = (vg_item3==1 | vg_item12==1 | vg_item14==1 | vg_item19==1)
  sum either


* Open Data B - Diagnosis and Treatment
  use "$prodata\vignettes.dta", clear
  count

  merge m:1 prov_id using "$prodata\SPP_prov_list"
  keep if _merge==3
  drop _merge

  merge m:1 prov_id using "$prodata\providers_interview", keepus(prov_id)
  keep if _merge==3
  drop _merge

  gen miss=.
  mat list table2
  gen dx_type_if=dx_type if dx_any==1
  gen tx_type_if=tx_type if tx_any==1
  local table2 "antib_dontknow miss dx_any dx_type dx_type_if miss tx_any tx_type tx_type_if"

  forvalues c=1/2 {
  local i 1
  foreach var of local table2 {

  quietly count if `var'!=.
    if r(N)==0 {
    local i = `i' + 1
    }
    else {

  quietly sum `var' if case==`c'

  if `c'==1 {
  mat table2[20+`i',1]=r(N)*r(mean)
  mat table2[20+`i',2]=r(mean)*100
  mat table2[20+`i',3]=r(sd)*100
  }
  if `c'==2 {
  mat table2[50+`i',1]=r(N)*r(mean)
  mat table2[50+`i',2]=r(mean)*100
  mat table2[50+`i',3]=r(sd)*100
  }
  local i = `i' +1
  }
  }
  }
  mat colnames table2 = N mean SD
  mat list table2

* Export table
  preserve
  drop _all
  svmat2 table2, names(col)

  foreach var of varlist mean SD {
  rename `var' `var'_old
  gen str8 `var'=string(`var'_old, "%9.1f")
  replace `var'="" if `var'=="."
  drop `var'_old
  }

  outsheet using "$output\table2.xls", replace
  restore



*********************************************************************
* Extra information - vignettes
* Average number of questions asked and examinations 
* performed for both cases
*********************************************************************
  use "$irtdata\vig_items_13.dta", clear

  merge 1:1 prov_id using "$prodata\SPP_prov_list"
  keep if _merge==3
  drop _merge

  merge 1:1 prov_id using "$prodata\providers_interview", keepus(prov_id)
  keep if _merge==3
  drop _merge

*(A) Diarrhea (15 med. questions and 5 examinations)
  egen medq1=rowtotal(vg_item1-vg_item10 vg_item12-vg_item14)
  egen mede1=rowtotal(vg_item16-vg_item20)

*(B) Pneumonia (11 med. questions and 9 examinations)
  egen medq2=rowtotal(vg_item21-vg_item25 vg_item27-vg_item31)
  egen mede2=rowtotal(vg_item32-vg_item40)

  mat medv=J(2,2,.)
  forvalues n=1/2 {
    sum medq`n'
    mat medv[1,`n']=r(mean)
    sum mede`n'
    mat medv[2,`n']=r(mean)
    }

  mat list medv


*********************************************************************
* Table 3: SPP
* Average Quality Outcomes
*********************************************************************

* Open Data
  use "$prodata\standardized_patient_b", clear
  count
  merge 1:1 prov_id using "$prodata\providers_interview", keepus(prov_id)
  keep if _merge==3
  drop _merge

* # of essential question asked
  cap drop nessential
  egen nessential=rowtotal(sp_item1-sp_item11 sp_item13-sp_item21)

  cap drop pessential
  gen     pessential=nessential/11 if case==1
  replace pessential=nessential/9 if case==2

  gen miss=.
  local table3 "visit_time nessential pessential nmedicines"
  local nvar : word count `table3'
  mat table3= J(`nvar'+1, 5,.)
  foreach c of numlist 1 2 {
  if `c'==1 local col "1"
  if `c'==2 local col "4"
  local i = 1
  foreach v of local table3 {
    qui sum `v' if case==`c'
      mat table3[`i',`col']=r(mean)
      mat table3[`i',`col'+1]=r(sd)
    local i = `i'+1
    }
    count if case==`c'
    mat table3[`nvar'+1,`col']=r(N)
    }

  mat colnames table3 = mean_c1 sd_c1 miss mean_c2 sd_s2

* Export matrix
  preserve
  drop _all
  svmat table3, names(col)
  drop miss

  foreach var of varlist mean_c1 sd_c1 mean_c2 sd_s2 {
  rename `var' `var'_old
  gen str8 `var'=string(`var'_old, "%9.1f")
  replace `var'="" if `var'=="."
  drop `var'_old
  }

  outsheet using "$output\table3.xls", replace
  restore



*********************************************************************
* Table 4: SPP Exit interview 
* Adherence to check list 
*********************************************************************

* Fraction of positive response
  mat table4=J(46,3,.)

  forvalues n=1/11 {
  quietly sum sp_item`n'
  mat table4[`n',1]=r(N)*r(mean)
  mat table4[`n',2]=r(mean)*100
  mat table4[`n',3]=r(sd)*100
  }

  forvalues n=13/21 {
  local m = `n'+12
  quietly sum sp_item`n'
  mat table4[`m',1]=r(N)*r(mean)
  mat table4[`m',2]=r(mean)*100
  mat table4[`m',3]=r(sd)*100
  }

  gen dx_type_if=dx_type if dx_any==1
  gen tx_type_if=tx_type if tx_any==1

  gen     other = sp_item12 if case==1
  replace other = sp_item22 if case==2

  local table4 "ask_child other miss dx_any dx_type dx_type_if miss tx_any tx_type tx_type_if"

  forvalues c=1/2 {
  local i 1
  foreach var of local table4 {

  quietly count if `var'!=.
    if r(N)==0 {
    local i = `i' + 1
    }
    else {

  quietly sum `var' if case==`c'

  if `c'==1 {
  mat table4[12+`i',1]=r(N)*r(mean)
  mat table4[12+`i',2]=r(mean)*100
  mat table4[12+`i',3]=r(sd)*100
  }
  if `c'==2 {
  mat table4[36+`i',1]=r(N)*r(mean)
  mat table4[36+`i',2]=r(mean)*100
  mat table4[36+`i',3]=r(sd)*100
  }
  local i = `i' +1
  }
  }
  }
  mat colnames table4 =  N mean SD
  mat list table4


* Export table
  preserve
  drop _all
  svmat2 table4, names(col)

  foreach var of varlist mean SD {
  rename `var' `var'_old
  gen str8 `var'=string(`var'_old, "%9.1f")
  replace `var'="" if `var'=="."
  drop `var'_old
  }

  outsheet using "$output\table4.xls", replace
  restore


*********************************************************************
* Table 5: SPP Exit interview + Vignette
* Type of treatment
*********************************************************************

* SPP Data
  mat table5=J(18,4,.)
    foreach c in 1 3 {
      forvalues v=1/8 {
      count if tx_detail`c'==`v'
      local n = r(N)
      count if tx_detail`c'!=.
      local N = r(N)

      if `c'==1 {
       mat table5[`v',3]=`n'
       mat table5[`v',4]=(`n'/`N')*100
       }

      if `c'==3 {
       mat table5[`v'+10,3]=`n'
       mat table5[`v'+10,4]=(`n'/`N')*100
       }

     }
     }


* Vignette data
  use "$prodata\vignettes.dta", clear

  merge m:1 prov_id using "$prodata\SPP_prov_list"
  keep if _merge==3
  drop _merge

  merge m:1 prov_id using "$prodata\providers_interview", keepus(prov_id)
  keep if _merge==3
  drop _merge


  forvalues c=1/2 {
  forvalues v=1/8 {
   count if tx_detail==`v' & case==`c'
   local n = r(N)
   count if tx_detail!=. & case==`c'
   local N = r(N)

   if `c'==1 {
   mat table5[`v',1]=`n'
   mat table5[`v',2]=(`n'/`N')*100
   }

   if `c'==2 {
   mat table5[`v'+10,1]=`n'
   mat table5[`v'+10,2]=(`n'/`N')*100
   }

   }
   }
   mat colnames table5 = n_vig mean_vig n_spp mean_spp
   mat list table5


* Export table
  preserve
  drop _all
  svmat2 table5, names(col)
  drop if _n>17

  foreach var of varlist mean_vig mean_spp {
  rename `var' `var'_old
  gen str8 `var'=string(`var'_old, "%9.1f")
  replace `var'="" if `var'=="."
  drop `var'_old
  }

  outsheet using "$output\table5.xls", replace
  restore


* Prtest Diarrhea
  use prov_id case tx_detail1 cluster using "$prodata\standardized_patient_b", clear
  merge 1:1 prov_id using "$prodata\providers_interview", keepus(prov_id)
  keep if _merge==3
  drop _merge
  count 
  drop if case==2
  count
  gen code7=(tx_detail1==7)
  sum code7
  gen source=1
  tempfile ssp_code7 
  drop case prov_id tx_detail1
  save "`ssp_code7'"


  use prov_id case tx_detail cluster using "$prodata\vignettes.dta", clear
  merge m:1 prov_id using "$prodata\SPP_prov_list"
  keep if _merge==3
  drop _merge
  merge m:1 prov_id using "$prodata\providers_interview", keepus(prov_id)
  keep if _merge==3
  drop _merge
  count
  drop if case==2
  count
  gen code7=(tx_detail==7)
  sum code7
  gen source=2
  tempfile vig_code7 
  drop case prov_id tx_detail
  save "`vig_code7'"

  append using "`ssp_code7'"

  prtest code7, by(source)
  clchi2 code7 source, cluster(cluster)
  clttest code7, cluster(cluster) by(source)



* Prtest Pneumonia
  use prov_id case tx_detail3 cluster using "$prodata\standardized_patient_b", clear
  merge 1:1 prov_id using "$prodata\providers_interview", keepus(prov_id)
  keep if _merge==3
  drop _merge
  drop if case==1
  gen code5=(tx_detail3==5)
  sum code5
  gen source=1
  tempfile ssp_code5
  drop case prov_id tx_detail3
  save "`ssp_code5'"

  use prov_id case tx_detail cluster using "$prodata\vignettes.dta", clear
  merge m:1 prov_id using "$prodata\SPP_prov_list"
  keep if _merge==3
  drop _merge
  merge m:1 prov_id using "$prodata\providers_interview", keepus(prov_id)
  keep if _merge==3
  drop _merge
  drop if case==1
  gen code5=(tx_detail==5)
  sum code5
  gen source=2
  tempfile vig_code5 
  drop case prov_id tx_detail
  save "`vig_code5'"

  append using "`ssp_code5'"
  prtest code5, by(source)
  clchi2 code5 source, cluster(cluster)
  clttest code5, cluster(cluster) by(source)



*=============================================================================*
*                                MERGING DATA
*=============================================================================*

* Open Providers Interview data and merge with SP
  use "$prodata\providers_interview", clear
  merge 1:1 prov_id using "$prodata\standardized_patient_b"
  keep if _merge==3
  drop _merge
  merge 1:1 prov_id case using "$prodata\vignettes", keepus(cleanliness)
  keep if _merge==3 
  drop _merge

* Merge Knowledge Score based on matched 12 questions 
  gen id =  prov_id
  merge 1:1 id using "$prodata\irt\vig_traits_1_q12", keepus(theta_mle theta_mle_std)
  rename theta_mle theta_mle1_q12
  rename theta_mle_std theta_mle_std1_q12
  drop if _merge==2
  drop _merge

  merge 1:1 id using "$prodata\irt\vig_traits_3_q12", keepus(theta_mle theta_mle_std)
  rename theta_mle theta_mle2_q12
  rename theta_mle_std theta_mle_std2_q12
  drop if _merge==2
  drop _merge

  egen    ks3_nostd =rowtotal(theta_mle1_q12 theta_mle2_q12)
  lab var ks3 "Knowledge Score based on each disease and matched 12 questions"

  egen    ks3 =rowtotal(theta_mle_std1_q12 theta_mle_std2_q12)
  lab var ks3 "Knowledge Score based on each disease and matched 12 questions"
  drop theta_mle_std1_q12 theta_mle_std2_q12


*********************************************************************
* Table 1 (cont.): Providers Characteristics - Second Part
* Format Mean(SD) for each group, Difference (95% CI) and p-value
*********************************************************************

* Knowledge and Performance Score according to medical qualification
  gen ks3_1=ks3_nostd if case==1
  gen ks3_2=ks3_nostd if case==2
  gen ps1=sp_theta_mle_q12 if case==1
  gen ps2=sp_theta_mle_q12 if case==2

  local i 25
  foreach var in ks3_nostd ks3_1 ks3_2 sp_theta_mle_q12 ps1 ps2 {
  quietly count if `var'!=.
    if r(N)==0 {
    local i = `i' + 1
    }
    else {

* Mean and Std. Dev.
  qui ttest `var', by(mqualif)
  matrix table1[`i',1] = r(mu_1)
  matrix table1[`i',2] = r(sd_1)
  matrix table1[`i',3] = r(N_1)
  matrix table1[`i',4] = r(mu_2)
  matrix table1[`i',5] = r(sd_2)
  matrix table1[`i',6] = r(N_2)

* Perform Mean Test and save results
  reg `var' mqualif, cluster(cluster)

* Mean difference
  matrix table1[`i',7] = _b[mqualif]

* Lower and upper bounds of the confidence interval
  local ci_lower = _b[mqualif] - invttail(e(df_r),0.025)*_se[mqualif]
  matrix table1[`i',8] = `ci_lower'
  local ci_upper = _b[mqualif] + invttail(e(df_r),0.025)*_se[mqualif]
  matrix table1[`i',9] = `ci_upper'

* P-value
  matrix table1[`i',10] = (2 * ttail(e(df_r), abs(_b[mqualif]/_se[mqualif])))

  local i = `i' + 1
  }
  }

  mat list table1

* Export matrix and compute significance
  preserve
  drop _all
  svmat2 table1, rnames(variables) names(col)
  order variables, first
  foreach var of varlist NMQ_mean-ci_upper {
  rename `var' `var'_old
  gen str8 `var'a=string(`var'_old, "%9.1f") in 1/24
  gen str8 `var'b=string(`var'_old, "%9.2f") in 25/30
  gen `var'=`var'a+`var'b
  replace `var'="" if `var'=="."
  drop `var'_old `var'a `var'b
  }
  
  rename pvalue pvalue_old
  gen str8 pvalue=string(pvalue_old, "%9.3f")
  replace pvalue="" if pvalue=="."
  drop pvalue_old

  outsheet using "$output\table1.xls", replace
  restore




*=============================================================================*
*                                REGRESSIONS
*=============================================================================*

* Dummy age
  egen agec=cut(age), at(20 30 40 50 60 80)
  tab agec, gen(agec)
  rename agec1 age20_29
  rename agec2 age30_39
  rename agec3 age40_49
  rename agec4 age50_59
  rename agec5 age60
  
* Define Regressors
  local reg1 "age20_29 age40_49 age50_59 age60 experience mqualif"
  local reg2 "age20_29 age40_49 age50_59 age60 experience mqualif work_hs npatient camps fac_gov cleanliness ks3"

* Hour of spp-provider interaction
  recode hour (7/9=1 "7-9 am") (10/12=2 "10-12 am") (13/15=3 "13-15 pm") (16/18=4 "16-18 pm"), gen(hour_cut)


*********************************************************************
* Table 6: SPP Exit interview & Providers interview
* OLS regression % of diagnostic questions and provider characteristics
*********************************************************************

* Percentage of selected items asked
  egen pq_spp=rmean(sp_item1-sp_item11 sp_item13-sp_item21)

* Regressions
  local dep "pq_spp"
  gen hour2=hour*hour
  gen hour3=hour2*hour

* OLS
  forvalues c=1/2 {
    forvalues n=1/2 {
    xi: reg `dep' `reg`n'' hour hour2 hour3 i.dow if case==`c', cluster(cluster) robust
    if `c'==1 & `n'==1 outreg2 using "$output\table6.xls", nocons cttop("OLS" "case `c'") bdec(3) sdec(3) stats(coef, se, ci_low ci_high, pval) sideway noaster replace
    else               outreg2 using "$output\table6.xls", nocons cttop("OLS" "case `c'") bdec(3) sdec(3) stats(coef, se, ci_low ci_high, pval) sideway noaster append
      }
    }

  erase "$output\table6.txt"

* Fractional Logit
  forvalues c=1/2 {
    forvalues n=1/2 {
    xi: glm `dep' `reg`n'' hour hour2 hour3 i.dow if case==`c', family(bin) link(logit) cluster(cluster) robust nolog eform
    mfx compute
    if `c'==1 & `n'==1 outreg2 using "$output\tableA3.xls", nocons cttop("FLM-ME" "case `c'") bdec(3) sdec(3) stats(coef, se, ci_low ci_high, pval) sideway noaster mfx replace
    else               outreg2 using "$output\tableA3.xls", nocons cttop("FLM-ME" "case `c'") bdec(3) sdec(3) stats(coef, se, ci_low ci_high, pval) sideway noaster mfx append
      }
    }

  erase "$output\tableA3.txt"


*********************************************************************
* Table A2: Vignettes & Providers interview
* OLS regression % of diagnostic questions and provider characteristics
*********************************************************************

  merge 1:1 prov_id using "$irtdata\vig_items_13", keepus(vg_item*)
  keep if _merge==3
  drop _merge

  egen pq_vig1=rmean(vg_item1-vg_item10 vg_item12-vg_item14)  if case==1
  egen pq_vig2=rmean(vg_item21-vg_item25 vg_item27-vg_item31) if case==2
  egen pq_vig=rowtotal(pq_vig1 pq_vig2)
  drop pq_vig1 pq_vig2

  local dep "pq_vig"


* OLS
  forvalues c=1/2 {
    forvalues n=1/2 {
    xi: reg `dep' `reg`n'' hour hour2 hour3 i.dow if case==`c', cluster(cluster) robust
    if `c'==1 & `n'==1 outreg2 using "$output\tableA2.xls", nocons cttop("OLS" "case `c'") bdec(3) sdec(3) stats(coef, se, ci_low ci_high, pval) sideway noaster replace
    else               outreg2 using "$output\tableA2.xls", nocons cttop("OLS" "case `c'") bdec(3) sdec(3) stats(coef, se, ci_low ci_high, pval) sideway noaster append
      }
    }

  erase "$output\tableA2.txt"


*********************************************************************
* Table 7: SPP Exit interview & Providers interview
* Unnecessary and harmful treatments 
*********************************************************************

* Dependent Variable
  gen tx_harm1=(tx_detail1>=3 & tx_detail1<=5 | tx_detail1==7) if case==1
  gen tx_harm2=(tx_detail3>=3 & tx_detail3<=5) if case==2
  egen tx_harm=rowtotal(tx_harm1 tx_harm2)

* Regressions
  local dep "tx_harm"
  gen nmqualif=(mqualif==0)

* Define Regressors
  local reg_o1 "age20_29 age40_49 age50_59 age60 experience nmqualif"
  local reg_o2 "age20_29 age40_49 age50_59 age60 experience nmqualif work_hs npatient camps fac_gov cleanliness ks3"

  forvalues c=1/2 {
    forvalues n=1/2 {
    logit `dep' `reg_o`n'' hour c.hour#c.hour c.hour#c.hour#c.hour i.dow if case==`c', cluster(cluster) or
    if `c'==1 & `n'==1 outreg2 using "$output\table7.xls", nocons cttop(LOGIT - ODD RATIO case `c') addstat("Pseudo R2",  e(r2_p)) bdec(3) sdec(3) stats(coef, se, ci_low ci_high, pval) sideway noaster eform replace
    else               outreg2 using "$output\table7.xls", nocons cttop(LOGIT - ODD RATIO case `c') addstat("Pseudo R2",  e(r2_p)) bdec(3) sdec(3) stats(coef, se, ci_low ci_high, pval) sideway noaster eform append
      }
    }

  erase "$output\table7.txt"


*********************************************************************
* Table A3: SPP, Vignette & Providers interview
* Performance 
*********************************************************************

* Regressions
  local dep "sp_theta_mle_q12_std"

  forvalues c=1/2 {
    forvalues n=1/2 {
    xi: reg `dep' `reg`n'' hour c.hour#c.hour c.hour#c.hour#c.hour i.dow if case==`c', cluster(cluster)
    if `c'==1 & `n'==1 outreg2 using "$output\tableA4.xls", nocons cttop("OLS" "case `c'") bdec(3) sdec(3) stats(coef, se, ci_low ci_high, pval) sideway noaster replace
    else               outreg2 using "$output\tableA4.xls", nocons cttop("OLS" "case `c'") bdec(3) sdec(3) stats(coef, se, ci_low ci_high, pval) sideway noaster append
      }
    }

  erase "$output\tableA4.txt"
